package com.zzyl.nursing.service.impl;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzyl.common.utils.DateUtils;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Contract;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.vo.TimeCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzyl.nursing.mapper.ReservationMemberMapper;
import com.zzyl.nursing.domain.ReservationMember;
import com.zzyl.nursing.service.IReservationMemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
/**
 * 预约信息Service业务层处理
 * 
 * @author dustin
 * @date 2025-08-29
 */
@Service
public class ReservationMemberServiceImpl extends ServiceImpl<ReservationMemberMapper,ReservationMember> implements IReservationMemberService
{
    @Autowired
    private ReservationMemberMapper reservationMemberMapper;

    /**
     * 查询预约信息
     * 
     * @param id 预约信息主键
     * @return 预约信息
     */
    @Override
    public ReservationMember selectReservationMemberById(Long id)
    {
        return getById(id);
    }

    /**
     * 查询预约信息列表
     * 
     * @param reservationMember 预约信息
     * @return 预约信息
     */
    @Override
    public List<ReservationMember> selectReservationMemberList(ReservationMember reservationMember)
    {
        return reservationMemberMapper.selectReservationMemberList(reservationMember);
    }

    /**
     * 新增预约信息
     * 
     * @param reservationMember 预约信息
     * @return 结果
     */
    @Override
    public int insertReservationMember(ReservationMember reservationMember)
    {
        return save(reservationMember)?1:0;
    }

    /**
     * 修改预约信息
     * 
     * @param reservationMember 预约信息
     * @return 结果
     */
    @Override
    public int updateReservationMember(ReservationMember reservationMember)
    {
        return updateById(reservationMember)?1:0;
    }

    /**
     * 批量删除预约信息
     * 
     * @param ids 需要删除的预约信息主键
     * @return 结果
     */
    @Override
    public int deleteReservationMemberByIds(Long[] ids)
    {
        return removeByIds(Arrays.asList(ids))?1:0;
    }

    /**
     * 删除预约信息信息
     * 
     * @param id 预约信息主键
     * @return 结果
     */
    @Override
    public int deleteReservationMemberById(Long id)
    {
        return removeById(id)?1:0;
    }



    @Override
    public Integer cancelledCount() {
        Long userId = UserThreadLocal.getUserId();
        Integer sum =reservationMemberMapper.cancelledCount(userId);
        return sum;
    }

    @Override
    public List<TimeCountVo> countByTime(Long time) {
        LocalDateTime date = Instant.ofEpochMilli(time).atZone(ZoneOffset.of("+8")).toLocalDateTime();
        List<TimeCountVo> list = reservationMemberMapper.countByTime(date);

        return list;
    }

    @Override
    public void add(ReservationDto dto) {
        dto.setCreateTime(LocalDateTime.now());
        dto.setUpdateTime(LocalDateTime.now());
        dto.setCreateBy(UserThreadLocal.getUserId());
        dto.setUpdateBy(UserThreadLocal.getUserId());
        dto.setStatus(0);
        reservationMemberMapper.add(dto);

    }

    @Override
    public List<ReservationMember> getPageList(ReservationMember reservationMember) {
        return reservationMemberMapper.getPageList(reservationMember);
    }

    @Override
    public void cannel(Long id) {
        reservationMemberMapper.cannel( id);
    }


}
